{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=2963
  Verdict: Accepted
}
var i,n,m:longint; a:array[0..1000010] of longint;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
readln(n);
fillchar(a,sizeof(a),0);
a[1]:=0;
a[2]:=1;
a[3]:=1;
for i:=4 to n do begin
    m:=a[i-1];
    if (not odd(i)) and (a[i div 2]<m) then m:=a[i div 2];
    if (i mod 3=0) and (a[i div 3]<m) then m:=a[i div 3];
    a[i]:=m+1;
end;
write(a[n]);
end.